package com.pinc.poop;

import java.io.File;

import android.content.Intent;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.text.format.Time;

public abstract class PwdProtectPreferenceActivity extends PreferenceActivity {

	@Override
	protected void onPause() {
		super.onPause();
		File val_file = new File(this.getCacheDir(), validate.VALID_FILE_NAME);
		Time now = new Time();
		now.setToNow();

		if ( val_file.exists())
		{
			val_file.setLastModified(now.toMillis(true));
		}
	}

	@Override
	protected void onResume() {
		super.onResume();

		if ( !PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pwd_protect", false))
			return;

		File val_file = new File(this.getCacheDir(), validate.VALID_FILE_NAME);
		Time now = new Time();
		now.setToNow();

		if ( !val_file.exists() || (now.toMillis(true) - val_file.lastModified()>validate.val_timeout))
		{
			val_file.delete();
			Intent intent = new Intent(this, validate.class);
			startActivity(intent);
		}
	}
}
